package com.pincai;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;


public class Work {

    private String path = "com.heiyu";
    private String filePath = "/Users/Mac/Desktop/heiyu/lianma_api/generator/src/main/resources/";
    private String targetPath = "/Users/Mac/Desktop/heiyu/lianma_api/common/src/main/java/com/heiyu";
    private String mapperPath ="/Users/Mac/Desktop/heiyu/lianma_api/common/src/main/resources/mapper/";

    //private String path = "com.train";
    //private String filePath = "C:/taizhou/quanyulvyou/trip/generator/src/main/resources/";
    //private String targetPath = "C:\\work\\train\\common\\src\\main\\java\\com\\train";
    //private String mapperPath ="C:\\work\\train\\common\\src\\main\\resources\\mapper/";
    private StringBuffer serviceImpl;
    private StringBuffer service;
    private StringBuffer action;
    private StringBuffer dao;
    private StringBuffer daoImpl;
    private StringBuffer entity;
    private StringBuffer mapper;
    private StringBuffer list;
    private StringBuffer test;
    private StringBuffer outter;
    private StringBuffer sql;
    private StringBuffer model;
    private StringBuffer facade;
    private final String propertie = "private nxtypenx nxnamenx; \r\n";
    private final String getSet = "public void setnxbignamenx(nxtypenx nxnamenx){\r\n this.nxnamenx = nxnamenx; \r\n} \r\n public nxtypenx getnxbignamenx(){\r\n return this.nxnamenx; \r\n} \r\n\r\n";
    private final String parseMStr = "if (!StringUtils.isEmpty(nxnamenx)) {\r\nmap.put(\"nxnamenx\",nxnamenx);\r\n}\r\n";
    private final String parseMInt = "if (!StringUtils.isEmpty(nxnamenx)) {\r\nmap.put(\"nxnamenx\",nxnamenx);\r\n}\r\n";
    private final String parseMObj = "if (null != nxnamenx) {\r\nmap.put(\"nxnamenx\",nxnamenx);\r\n}\r\n";
    private final String modelParseMStr = "pattern = Pattern.compile(ValityRules.EMPTY);\r\n m = pattern.matcher(nxnamenx);\r\n if(!m.matches()){\r\n\r\n map.put(\"nxnamenx\",\"wrong msg\");\r\n}\r\n";
    private final String modelParseMInt = "pattern = Pattern.compile(ValityRules.EMPTY);\r\n m = pattern.matcher(\"\"+nxnamenx);\r\n if(!m.matches()){\r\n\r\n map.put(\"nxnamenx\",\"wrong msg\");\r\n}\r\n";
    private final String modelParseMObj = "if (null == nxnamenx) {\r\nmap.put(\"nxnamenx\",\"nxnamenx不能为空\");\r\n}\r\n";
    private final String coverParseInt = "if (entity.getnxnamenx()!=0) {\r\n model.setnxnamenx(entity.getnxnamenx()); \r\n}\r\n";// 把entity转成model
    private final String coverParseStr = "if (!StringUtils.isEmpty(entity.getnxnamenx())) {\r\n model.setnxnamenx(entity.getnxnamenx()); \r\n}\r\n";// 把entity转成model
    private final String coverParseObj = "if (null != entity.getnxnamenx()) {\r\n model.setnxnamenx(entity.getnxnamenx()); \r\n}\r\n";// 把entity转成model
    private final String recoverParseInt = "if (entity.getnxnamenx()!=0) {\r\n model.setnxnamenx(entity.getnxnamenx()); \r\n}\r\n";// //把entity转成model
    private final String recoverParseStr = "if (!StringUtils.isEmpty(entity.getnxnamenx())) {\r\n model.setnxnamenx(entity.getnxnamenx()); \r\n}\r\n";// //把entity转成model
    private final String recoverParseObj = "if (null != entity.getnxnamenx()) {\r\n model.setnxnamenx(entity.getnxnamenx()); \r\n}\r\n";// //把entity转成model
    private final String buildPojo = "nxtablenx.setnxColumnnx(nxdatanx);\r\n ";
    private final Utils utils;
    private int counter = 1;
    private final boolean haveTFlag = true;

    public Work() {
        init();
        utils = new Utils();
        Map<String, List<String[]>> map = utils.doAll();
        Iterator<Entry<String, List<String[]>>> it = map.entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, List<String[]>> en = (Entry<String, List<String[]>>) it
                    .next();
            makeUpActionService(en.getKey(), en.getKey().substring(0, 1)
                    .toLowerCase()
                    + en.getKey().substring(1));
            makeUpEntityMapper(en.getKey(), en.getKey().substring(0, 1)
                    .toLowerCase()
                    + en.getKey().substring(1), en.getValue());
        }
    }

    public void init() {
        serviceImpl = new StringBuffer();
        service = new StringBuffer();
        action = new StringBuffer();
        dao = new StringBuffer();
        daoImpl = new StringBuffer();
        entity = new StringBuffer();
        mapper = new StringBuffer();
        list = new StringBuffer();
        test = new StringBuffer();
        outter = new StringBuffer();
        model = new StringBuffer();
        facade = new StringBuffer();
        File file = new File(filePath + "service.txt");
        try {
            FileInputStream is = new FileInputStream(file);
            byte[] b = new byte[is.available()];
            while (is.read(b) != -1) {
                service.append(new String(b));
            }
            is.close();
            is = new FileInputStream(new File(filePath + "serviceImp.txt"));
            b = null;
            b = new byte[is.available()];
            while (is.read(b) != -1) {
                serviceImpl.append(new String(b));
            }
            is.close();
            is = new FileInputStream(new File(filePath + "action.txt"));
            b = null;
            b = new byte[is.available()];
            while (is.read(b) != -1) {
                action.append(new String(b));
            }
            is.close();
            is = new FileInputStream(new File(filePath + "dao.txt"));
            b = null;
            b = new byte[is.available()];
            while (is.read(b) != -1) {
                dao.append(new String(b));
            }
            is.close();
            is = new FileInputStream(new File(filePath + "daoImpl.txt"));
            b = null;
            b = new byte[is.available()];
            while (is.read(b) != -1) {
                daoImpl.append(new String(b));
            }
            is.close();
            is = null;
            b = null;
            is = new FileInputStream(new File(filePath + "entity.txt"));
            b = new byte[is.available()];
            while (is.read(b) != -1) {
                entity.append(new String(b));
            }
            is.close();
            is = null;
            b = null;
            is = new FileInputStream(new File(filePath + "mapper.txt"));
            b = new byte[is.available()];
            while (is.read(b) != -1) {
                mapper.append(new String(b));
            }
            is.close();
            is = null;
            b = null;
            is = new FileInputStream(new File(filePath + "list.txt"));
            b = new byte[is.available()];
            while (is.read(b) != -1) {
                list.append(new String(b));
            }
            is.close();
            is = null;
            b = null;
            is = new FileInputStream(new File(filePath + "interface.txt"));
            b = new byte[is.available()];
            while (is.read(b) != -1) {
                outter.append(new String(b));
            }
            is.close();
            is = null;
            b = null;
            is = new FileInputStream(new File(filePath + "model.txt"));
            b = new byte[is.available()];
            while (is.read(b) != -1) {
                model.append(new String(b));
            }
            is.close();
            is = null;
            b = null;
            is = new FileInputStream(new File(filePath + "facade.txt"));
            b = new byte[is.available()];
            while (is.read(b) != -1) {
                facade.append(new String(b));
            }
            is.close();
            is = null;
            b = null;
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    // 生产action\service\serviceimpl\dao\daoimpl的java文件
    public void makeUpActionService(String bigTable, String table) {
        String s = service.toString();
        String simp = serviceImpl.toString();
        String a = action.toString();
        String d = dao.toString();
        String dim = daoImpl.toString();
        String out = outter.toString();
        String faca = facade.toString();

        a = replaceText(a, bigTable, table);
        out = replaceText(out, bigTable, table);
        s = replaceText(s, bigTable, table);
        simp = replaceText(simp, bigTable, table);
        d = replaceText(d, bigTable, table);
        dim = replaceText(dim, bigTable, table);
        faca = replaceText(faca, bigTable, table);

        //createWriteFile(s, bigTable, "Service.java");
        //createWriteFile(simp, bigTable, "ServiceImpl.java");
        //createWriteFile(a, bigTable, "Controller.java");
        createWriteFile(d, bigTable, "Mapper.java");
        createWriteFile(dim, bigTable, "DaoImpl.java");
        //createWriteFile(out, bigTable, "Interface.java");
        //createWriteFile(faca, bigTable, "FacadeImpl.java");
        a = null;
        s = null;
        simp = null;
        out = null;
    }

    // 生产实体类文件
    public void makeUpEntityMapper(String bigTable, String table,
                                   List<String[]> list) {
        String[] labels = list.get(0);
        String[] types = list.get(1);
        String[] columns = list.get(2);
        String properties = " ";
        String getsets = " ";
        String parseMap = " ";
        String allColumn = " ";
        String wherecase = " ";
        String insertcolumns = " ";
        String insertvalues = " ";
        String updateCase = " ";
        StringBuilder buildPojoData = new StringBuilder();
        String modelParseMap = " ";
        String cover = "";
        String recover = "";
        for (int i = 0; i < labels.length; i++) {
            properties += propertie.replaceAll("nxtypenx", types[i])
                    .replaceAll("nxnamenx", labels[i]);
            getsets += getSet
                    .replaceAll("nxtypenx", types[i])
                    .replaceAll("nxnamenx", labels[i])
                    .replaceAll(
                            "nxbignamenx",
                            labels[i].substring(0, 1).toUpperCase()
                                    + labels[i].substring(1));

            if (types[i].equals("Integer")) {
                parseMap += parseMInt.replaceAll("nxnamenx", labels[i]);
                modelParseMap += modelParseMInt.replaceAll("nxnamenx",
                        labels[i]);
                cover += coverParseInt.replace(
                        "nxnamenx",
                        labels[i].substring(0, 1).toUpperCase()
                                + labels[i].substring(1));
                recover += recoverParseInt
                        .replace("nxnamenx", labels[i].substring(0, 1)
                                .toUpperCase() + labels[i].substring(1));
                wherecase += "<if test=\"" + labels[i] + " != null  \"> \r\n" + "AND " + columns[i]
                        + " = #{" + labels[i] + ",jdbcType=INTEGER}\r\n"
                        + "</if>\r\n";
                insertvalues += "<if test=\""+labels[i]+" != null \"> \r\n#{" + labels[i] + ",jdbcType=INTEGER},\r\n</if>";
                    updateCase += "<if test=\"" + labels[i] + " != null and "
                            + labels[i] + " != 0 \"> \r\n" + " " + columns[i]
                            + " = #{" + labels[i] + ",jdbcType=INTEGER} ,\r\n"
                            + "</if>\r\n";
                buildPojoData.append(buildPojo.replace("nxColumnnx",
                        Utils.autoUpCase(labels[i],false)).replace("nxdatanx", "1"));
            } else if (types[i].equals("Long")) {
                parseMap += parseMInt.replaceAll("nxnamenx", labels[i]);
                modelParseMap += modelParseMInt.replaceAll("nxnamenx",
                        labels[i]);
                cover += coverParseInt.replace(
                        "nxnamenx",
                        labels[i].substring(0, 1).toUpperCase()
                                + labels[i].substring(1));
                recover += recoverParseInt
                        .replace("nxnamenx", labels[i].substring(0, 1)
                                .toUpperCase() + labels[i].substring(1));
                wherecase += "<if test=\"" + labels[i] + " != null  \"> \r\n" + "AND " + columns[i]
                        + " = #{" + labels[i] + ",jdbcType=BIGINT}\r\n"
                        + "</if>\r\n";
                insertvalues += "<if test=\""+labels[i]+" != null \"> \r\n#{" + labels[i] + ",jdbcType=BIGINT},\r\n</if>";
                    updateCase += "<if test=\"" + labels[i] + " != null and "
                            + labels[i] + " != 0 \"> \r\n" + " " + columns[i]
                            + " = #{" + labels[i] + ",jdbcType=BIGINT} ,\r\n"
                            + "</if>\r\n";
                buildPojoData.append(buildPojo.replace("nxColumnnx",
                        Utils.autoUpCase(labels[i],false)).replace("nxdatanx", "1"));
            } else if (types[i].equals("String")) {
                parseMap += parseMStr.replaceAll("nxnamenx", labels[i]);
                modelParseMap += modelParseMStr.replaceAll("nxnamenx",
                        labels[i]);
                cover += coverParseStr.replace(
                        "nxnamenx",
                        labels[i].substring(0, 1).toUpperCase()
                                + labels[i].substring(1));
                recover += recoverParseStr
                        .replace("nxnamenx", labels[i].substring(0, 1)
                                .toUpperCase() + labels[i].substring(1));
                    wherecase += "<if test=\"" + labels[i] + " != null and "
                            + labels[i] + " !='' \"> \r\n" + "AND "
                            + columns[i] + " = #{" + labels[i]
                            + ",jdbcType=VARCHAR}\r\n" + "</if>\r\n";
                insertvalues += "<if test=\""+labels[i]+" != null \"> \r\n#{" + labels[i] + ",jdbcType=VARCHAR},\r\n</if>";
                    buildPojoData.append(buildPojo.replace("nxColumnnx",
                            Utils.autoUpCase(labels[i],false)).replace("nxdatanx",
                            "\"test\""));
                updateCase += "<if test=\"" + labels[i] + " != null and "
                        + labels[i] + " !=''   \"> \r\n" + " " + columns[i]
                        + " = #{" + labels[i] + ",jdbcType=VARCHAR} ,\r\n"
                        + "</if>\r\n";
            } else if (types[i].equals("float")) {
                parseMap += parseMStr.replaceAll("nxnamenx", labels[i]);
                modelParseMap += modelParseMStr.replaceAll("nxnamenx",
                        labels[i]);
                cover += coverParseStr.replace(
                        "nxnamenx",
                        labels[i].substring(0, 1).toUpperCase()
                                + labels[i].substring(1));
                recover += recoverParseStr
                        .replace("nxnamenx", labels[i].substring(0, 1)
                                .toUpperCase() + labels[i].substring(1));
                    wherecase += "<if test=\"" + labels[i] + " != null and "
                            + labels[i] + " !='' \"> \r\n" + "AND "
                            + columns[i] + " = #{" + labels[i]
                            + ",jdbcType=DECIMAL}\r\n" + "</if>\r\n";
                insertvalues += "<if test=\"" + labels[i] + " != null\">#{" + labels[i] + ",jdbcType=DECIMAL},</if>";

                    buildPojoData.append(buildPojo.replace("nxColumnnx",
                            Utils.autoUpCase(labels[i],false)).replace("nxdatanx",
                            "0.01f"));

                updateCase += "<if test=\"" + labels[i] + " != null and "
                        + labels[i] + " !=''   \"> \r\n" + " " + columns[i]
                        + " = #{" + labels[i] + ",jdbcType=DECIMAL} ,\r\n"
                        + "</if>\r\n";
            } else if (types[i].equals("DECIMAL")) {
                parseMap += parseMStr.replaceAll("nxnamenx", labels[i]);
                modelParseMap += modelParseMStr.replaceAll("nxnamenx",
                        labels[i]);
                cover += coverParseStr.replace(
                        "nxnamenx",
                        labels[i].substring(0, 1).toUpperCase()
                                + labels[i].substring(1));
                recover += recoverParseStr
                        .replace("nxnamenx", labels[i].substring(0, 1)
                                .toUpperCase() + labels[i].substring(1));
                    wherecase += "<if test=\"" + labels[i] + " != null and "
                            + labels[i] + " !='' \"> \r\n" + "AND "
                            + columns[i] + " = #{" + labels[i]
                            + ",jdbcType=DECIMAL}\r\n" + "</if>\r\n";
                insertvalues += "<if test=\""+labels[i]+"!= null\">#{" + labels[i] + ",jdbcType=DECIMAL},</if>\r\n";
                    buildPojoData.append(buildPojo.replace("nxColumnnx",
                            Utils.autoUpCase(labels[i],false)).replace("nxdatanx",
                            "\"test\""));

                updateCase += "<if test=\"" + labels[i] + " != null and "
                        + labels[i] + " !=''   \"> \r\n" + " " + columns[i]
                        + " = #{" + labels[i] + ",jdbcType=DECIMAL} ,\r\n"
                        + "</if>\r\n";
            } else {
                if (types[i].equals("Date")) {
                    wherecase += "<if test=\"" + labels[i]
                            + " != null  \"> \r\n" + "AND " + columns[i]
                            + " = #{" + labels[i] + ",jdbcType=TIMESTAMP}\r\n"
                            + "</if>\r\n";
                    insertvalues +=  "<if test=\"" + labels[i] + " != null\">#{" + labels[i] + ",jdbcType=TIMESTAMP},</if>\r\n";
                    updateCase += "<if test=\"" + labels[i]
                            + " != null  \"> \r\n" + " " + columns[i] + " = #{"
                            + labels[i] + ",jdbcType=TIMESTAMP} ,\r\n"
                            + "</if>\r\n";
                }
                parseMap += parseMObj
                        .replace("nxnamenx",
                                "@JSONField(format=\"yyyyMMddHHmmss\")\r\n"
                                        + labels[i]);
                modelParseMap += modelParseMObj
                        .replaceAll("nxnamenx",
                                "@JSONField(format=\"yyyyMMddHHmmss\")\r\n"
                                        + labels[i]);
                cover += coverParseObj.replace(
                        "nxnamenx",
                        labels[i].substring(0, 1).toUpperCase()
                                + labels[i].substring(1));
                recover += recoverParseObj
                        .replace("nxnamenx", labels[i].substring(0, 1)
                                .toUpperCase() + labels[i].substring(1));
                buildPojoData.append(buildPojo.replace("nxColumnnx",
                        Utils.autoUpCase(labels[i],false)).replace("nxdatanx",
                        "new Date()"));
            }
            allColumn += columns[i] + " " + labels[i] + ",\r\n";
            insertcolumns +="<if test=\""+labels[i]+"!=null \">"+ columns[i] + ",</if>\r\n";
        }
        String testCase = test.toString();
        String enty = entity.toString();
        enty = replaceText(enty, bigTable, table);
        enty = enty.replace("nxcoloumnnx", properties);
        enty = enty.replace("nxgetsetnx", getsets);
        enty = enty.replace("nxparseMapnx", parseMap);
        String mod = model.toString();
        mod = replaceText(mod, bigTable, table);
        mod = mod.replace("nxcoloumnnx", properties);
        mod = mod.replace("nxgetsetnx", getsets);
        mod = mod.replace("nxparseMapnx", modelParseMap);
        mod = mod.replace("nxcovernx", cover);
        mod = mod.replace("nxrecovernx", recover);
        String mapperT = mapper.toString();
        mapperT = replaceText(mapperT, bigTable, table);
        allColumn = allColumn.trim();
        mapperT = mapperT.replace("nxallcolumnnx",
                allColumn.substring(0, allColumn.length() - 1));
        mapperT = mapperT.replace("nxwherecasenx", wherecase);
        if(insertcolumns.endsWith(",\r\n")){
            mapperT = mapperT.replace("nxinsertcolumnsnx", insertcolumns.substring(0,insertcolumns.length()-",\r\n".length()));
        }else{
            mapperT = mapperT.replace("nxinsertcolumnsnx", insertcolumns);
        }

        if(insertvalues.endsWith(",\r\n")){
            mapperT = mapperT.replace("nxinsertvaluesnx", insertvalues.substring(0,insertvalues.length()-",\r\n".length()));
        }else{
            mapperT = mapperT.replace("nxinsertvaluesnx", insertvalues);
        }

        mapperT = mapperT.replace("nxupdatenx", updateCase);
        mapperT = mapperT.replace("nxpagewherenx", wherecase);
        if (haveTFlag) {
            mapperT = mapperT.replaceAll("nxbiaomingnx",
                    utils.map.get(bigTable).toString());
        } else {
            mapperT = mapperT.replaceAll("nxbiaomingnx", utils.map
                    .get(bigTable).toString());
        }

        mapperT = mapperT.replaceAll("nxupdateCasenx", updateCase);
        testCase = testCase.replace("nxcolumnsnx", buildPojoData.toString());
        testCase = replaceText(testCase, bigTable, table);

        if (sql == null) {
            sql = new StringBuffer("delet from t_grant_info where 1=1; \r\n");
        }
        StringBuffer statement = new StringBuffer();
        String stat1 = "insert into t_grant_info(name,url,code,flag,enabled,deleted,create_time,create_by,modify_by,modify_time,version) values('nxtablenx','/nxtablenxAction/add.do','1nxcodenx','F','T','F',now(),'system','system',now(),1);\r\n";
        String stat2 = "insert into t_grant_info(name,url,code,flag,enabled,deleted,create_time,create_by,modify_by,modify_time,version) values('nxtablenx','/nxtablenxAction/doAdd.do','2nxcodenx','F','T','F',now(),'system','system',now(),1);\r\n";
        String stat3 = "insert into t_grant_info(name,url,code,flag,enabled,deleted,create_time,create_by,modify_by,modify_time,version) values('nxtablenx','/nxtablenxAction/edit.do','3nxcodenx','F','T','F',now(),'system','system',now(),1);\r\n";
        String stat4 = "insert into t_grant_info(name,url,code,flag,enabled,deleted,create_time,create_by,modify_by,modify_time,version) values('nxtablenx','/nxtablenxAction/doEdit.do','4nxcodenx','F','T','F',now(),'system','system',now(),1);\r\n";
        String stat5 = "insert into t_grant_info(name,url,code,flag,enabled,deleted,create_time,create_by,modify_by,modify_time,version) values('nxtablenx','/nxtablenxAction/del.do','5nxcodenx','F','T','F',now(),'system','system',now(),1);\r\n";
        String stat6 = "insert into t_grant_info(name,url,code,flag,enabled,deleted,create_time,create_by,modify_by,modify_time,version) values('nxtablenx','/nxtablenxAction/doDel.do','6nxcodenx','F','T','F',now(),'system','system',now(),1);\r\n";
        String stat7 = "insert into t_grant_info(name,url,code,flag,enabled,deleted,create_time,create_by,modify_by,modify_time,version) values('nxtablenx','/nnxtablenxAction/list.do','7nxcodenx','F','T','F',now(),'system','system',now(),1);\r\n";
        String stat8 = "insert into t_grant_info(name,url,code,flag,enabled,deleted,create_time,create_by,modify_by,modify_time,version) values('nxtablenx','/nxtablenxAction/grid.do','8nxcodenx','F','T','F',now(),'system','system',now(),1);\r\n";
        String stat9 = "insert into t_grant_info(name,url,code,flag,enabled,deleted,create_time,create_by,modify_by,modify_time,version) values('nxtablenx','/nxtablenxInterface/add.do','9nxcodenx','F','T','F',now(),'system','system',now(),1);\r\n";
        String stat10 = "insert into t_grant_info(name,url,code,flag,enabled,deleted,create_time,create_by,modify_by,modify_time,version) values('nxtablenx','/nxtablenxInterface/update.do','10nxcodenx','F','T','F',now(),'system','system',now(),1);\r\n";
        String stat11 = "insert into t_grant_info(name,url,code,flag,enabled,deleted,create_time,create_by,modify_by,modify_time,version) values('nxtablenx','/nxtablenxInterface/delete.do','11nxcodenx','F','T','F',now(),'system','system',now(),1);\r\n";
        String stat12 = "insert into t_grant_info(name,url,code,flag,enabled,deleted,create_time,create_by,modify_by,modify_time,version) values('nxtablenx','/nxtablenxInterface/updateById.do','12nxcodenx','F','T','F',now(),'system','system',now(),1);\r\n";
        String stat13 = "insert into t_grant_info(name,url,code,flag,enabled,deleted,create_time,create_by,modify_by,modify_time,version) values('nxtablenx','/nxtablenxInterface/list.do','13nxcodenx','F','T','F',now(),'system','system',now(),1);\r\n";

        statement.append(stat1).append(stat2).append(stat3).append(stat4)
                .append(stat5).append(stat6).append(stat7).append(stat8)
                .append(stat9).append(stat10).append(stat11).append(stat12)
                .append(stat13);
        sql.append(statement.toString().replaceAll("nxtablenx", table)
                .replaceAll("nxcodenx", "" + counter));
        counter++;
        createWriteFile(enty, bigTable, ".java");
        //
        // createWriteFile(mod, bigTable, "Model.java");
        createWriteFile(mapperT, bigTable, ".xml");
        //createWriteFile(testCase, bigTable, "Test.java");
    }

    public static void main(String[] args) {
        Work w = new Work();
    }

    // 替换类名和变量名
    public String replaceText(String s, String bigTable, String table) {
        s = s.replaceAll("nxbigTablenx", bigTable);
        s = s.replaceAll("nxtablenx", table);
        s = s.replaceAll("nxpathnx", path);
        return s;
    }

    // 生成文件
    public boolean createWriteFile(String s, String bigTable, String name) {
        try {
            File f = null;
            if (name.endsWith(".xml")) {
                f = new File(mapperPath + bigTable
                        + name);
            } else {
                if (name.endsWith("ServiceImpl.java"))
                    f = new File(this.targetPath + "/service/impl/" + bigTable
                            + name);
                else if (name.endsWith("Service.java"))
                    f = new File(targetPath + "/service/" + bigTable + name);
                else if (name.endsWith("DaoImpl.java"))
                    f = new File(targetPath + "/dao/impl/" + bigTable + name);
                else if (name.endsWith("Mapper.java"))
                    f = new File(targetPath + "/dao/" + bigTable + name);
                else if (name.endsWith("Action.java"))
                    f = new File(targetPath + "/action/" + bigTable + name);
                else if (name.endsWith(".xml"))
                    f = new File(targetPath + "/entity/sqlMapper/" + bigTable
                            + name);
                else if (name.endsWith("Test.java"))
                    f = new File(targetPath.replace("\\src\\main\\java",
                            "\\src\\test\\java") + "/test/" + bigTable + name);
                else if (name.endsWith("Interface.java"))
                    f = new File(targetPath + "/outter/" + bigTable + name);
                else if (name.endsWith("Model.java"))
                    f = new File(targetPath + "/model/" + bigTable + name);
                else if (name.endsWith("FacadeImpl.java"))
                    f = new File(targetPath + "/facade/impl/" + bigTable + name);
                else
                    f = new File(targetPath + "/entity/" + bigTable + name);
                // return true;
            }

            if (!f.exists()) {
                f.createNewFile();
            } else {
                return true;
            }

            FileOutputStream fos = new FileOutputStream(f);
            fos.write(s.getBytes());
            fos.flush();
            fos.close();
            fos = null;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
}
